package org.inh.ld20.dangerousbrother;

import java.awt.event.KeyEvent;

public class Input {
	public static final int ENTER = 0;
	
	public static final int LEFT = 1;
	public static final int RIGHT = 2;
	public static final int JUMP = 3;
	
	public static final int COLLECT = 4;
	public static final int THROW = 5;
	
    public static final int ESCAPE = 6;

    public boolean[] buttons = new boolean[64];
    public boolean[] oldButtons = new boolean[64];

    public void set(int key, boolean down) {
        int button = -1;
        
        if(key == KeyEvent.VK_ENTER) button = ENTER;

        if(key == KeyEvent.VK_A) button = LEFT;
        if(key == KeyEvent.VK_D) button = RIGHT;
        
        if(key == KeyEvent.VK_LEFT) button = LEFT;
        if(key == KeyEvent.VK_RIGHT) button = RIGHT;
        
        if(key == KeyEvent.VK_SPACE) button = JUMP;
        
        if(key == KeyEvent.VK_E) button = COLLECT;

        if (key == KeyEvent.VK_ESCAPE) button = ESCAPE;

        if (button >= 0) {
            buttons[button] = down;
        }
    }

    public void tick() {
        for (int i = 0; i < buttons.length; i++) {
            oldButtons[i] = buttons[i];
        }
    }


    public void releaseAllKeys() {
        for (int i = 0; i < buttons.length; i++) {
            buttons[i] = false;
        }
    }
}
